<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Ankoder::CoreExtension::ArrayExtension</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Ankoder::CoreExtension::ArrayExtension</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/lib/ankoder/ext_rb.html">
                lib/ankoder/ext.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000003">find_with_conditions</a>&nbsp;&nbsp;
      <a href="#M000002">find_with_options</a>&nbsp;&nbsp;
      <a href="#M000006">include_ankoder_object</a>&nbsp;&nbsp;
      <a href="#M000004">limit</a>&nbsp;&nbsp;
      <a href="#M000005">order</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000003" class="method-detail">
        <a name="M000003"></a>

        <div class="method-heading">
          <a href="#M000003" class="method-signature">
          <span class="method-name">find_with_conditions</span><span class="method-args">(conditions={})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Select <a href="../Base.html">Ankoder#Base</a> object containing the
conditions
</p>
<pre>
  Profile.find(:all).find_with_conditions(:name =&gt; &quot;aaa&quot;)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000003-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ankoder/ext.rb, line 67</span>
67:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_with_conditions</span>(<span class="ruby-identifier">conditions</span>={})
68:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conditions</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">conditions</span>.<span class="ruby-identifier">empty?</span>
69:         <span class="ruby-identifier">res</span> = []
70:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">object</span><span class="ruby-operator">|</span>
71:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
72:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">conditions</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>]
73:               <span class="ruby-identifier">condition</span> = []
74:               <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">conditions</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">conditions</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>].<span class="ruby-identifier">to_s</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/([&lt;|&gt;|&lt;=|&gt;=|==]+)[\s]*([0-9]+)$/</span>
75:                 <span class="ruby-identifier">conditions</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>].<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot; and &quot;</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
76:                   <span class="ruby-identifier">c</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/([&lt;|&gt;|&lt;=|&gt;=|==]+)[\s]*([0-9]+)$/</span>)
77:                   <span class="ruby-identifier">condition</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{v} #{$1} #{$2}&quot;</span>
78:                 <span class="ruby-keyword kw">end</span>
79:                 <span class="ruby-identifier">res</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">object</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">condition</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot; and &quot;</span>))
80:               <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">conditions</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>)
81:                 <span class="ruby-identifier">res</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">object</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">conditions</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>]
82:               <span class="ruby-keyword kw">else</span>
83:                 <span class="ruby-identifier">res</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">object</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">v</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">conditions</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>]
84:               <span class="ruby-keyword kw">end</span>
85:             <span class="ruby-keyword kw">end</span>
86:           <span class="ruby-keyword kw">end</span>
87:         <span class="ruby-keyword kw">end</span>
88:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">res</span>
89:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000002" class="method-detail">
        <a name="M000002"></a>

        <div class="method-heading">
          <a href="#M000002" class="method-signature">
          <span class="method-name">find_with_options</span><span class="method-args">(options={})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000002-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ankoder/ext.rb, line 53</span>
53:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_with_options</span>(<span class="ruby-identifier">options</span>={})
54:         <span class="ruby-identifier">collection</span> = <span class="ruby-keyword kw">self</span>
55:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:conditions</span>]
56:           <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:conditions</span>].<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
57:             <span class="ruby-identifier">collection</span> = <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">find_with_conditions</span>(<span class="ruby-identifier">k</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">v</span>)
58:           <span class="ruby-keyword kw">end</span>
59:         <span class="ruby-keyword kw">end</span>
60:         <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">limit</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:limit</span>]).<span class="ruby-identifier">order</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:order</span>]).<span class="ruby-identifier">include_ankoder_object</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:include</span>])
61:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000006" class="method-detail">
        <a name="M000006"></a>

        <div class="method-heading">
          <a href="#M000006" class="method-signature">
          <span class="method-name">include_ankoder_object</span><span class="method-args">(inc=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000006-source">
<pre>
     <span class="ruby-comment cmt"># File lib/ankoder/ext.rb, line 112</span>
112:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include_ankoder_object</span>(<span class="ruby-identifier">inc</span>=<span class="ruby-keyword kw">nil</span>)
113:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">inc</span>.<span class="ruby-identifier">nil?</span>
114:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">object</span><span class="ruby-operator">|</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">include_ankoder_object</span>(<span class="ruby-identifier">inc</span>)}
115:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000004" class="method-detail">
        <a name="M000004"></a>

        <div class="method-heading">
          <a href="#M000004" class="method-signature">
          <span class="method-name">limit</span><span class="method-args">(lim=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000004-source">
<pre>
    <span class="ruby-comment cmt"># File lib/ankoder/ext.rb, line 91</span>
91:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">limit</span>(<span class="ruby-identifier">lim</span>=<span class="ruby-keyword kw">nil</span>)
92:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">lim</span>.<span class="ruby-identifier">nil?</span>
93:         <span class="ruby-keyword kw">self</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">lim</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>]
94:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000005" class="method-detail">
        <a name="M000005"></a>

        <div class="method-heading">
          <a href="#M000005" class="method-signature">
          <span class="method-name">order</span><span class="method-args">(order_str=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000005-source">
<pre>
     <span class="ruby-comment cmt"># File lib/ankoder/ext.rb, line 96</span>
 96:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">order</span>(<span class="ruby-identifier">order_str</span>=<span class="ruby-keyword kw">nil</span>)
 97:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">order_str</span>.<span class="ruby-identifier">nil?</span>
 98:         <span class="ruby-identifier">field</span>, <span class="ruby-identifier">sort</span> = <span class="ruby-identifier">order_str</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/([a-z0-9_]+)([\s+]*[ASC|DESC]*)/i</span>).<span class="ruby-identifier">to_a</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
 99:         <span class="ruby-identifier">sort</span> = <span class="ruby-value str">&quot;ASC&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sort</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">sort</span>.<span class="ruby-identifier">empty?</span>
100:         <span class="ruby-keyword kw">begin</span>
101:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">sort</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">x</span>,<span class="ruby-identifier">y</span><span class="ruby-operator">|</span>
102:             <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">sort</span>
103:             <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/ASC/i</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">field</span>) <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">y</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">field</span>)
104:             <span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/DESC/i</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">y</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">field</span>) <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">field</span>)
105:             <span class="ruby-keyword kw">end</span>
106:           <span class="ruby-keyword kw">end</span>
107:         <span class="ruby-keyword kw">rescue</span>
108:           <span class="ruby-keyword kw">self</span>
109:         <span class="ruby-keyword kw">end</span>
110:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>